import tkinter.messagebox

class LoginBackend:
    """Backend logic for login management"""
    
    def __init__(self):
        # Simple user database - in a real application, this would be stored in a database
        self.users = {
            'admin': 'admin',
            'root': 'root',
            'doctor': 'doctor',
            'nurse': 'nurse'
        }
    
    def validate_login(self, username, password):
        """Validate user login credentials"""
        try:
            if not username or not password:
                return False, "Username and password are required"
            
            username = username.strip()
            password = password.strip()
            
            if username in self.users and self.users[username] == password:
                # Determine user type based on username
                user_type = 'root' if username == 'root' else 'admin'
                return True, user_type
            else:
                return False, "Invalid username or password"
                
        except Exception as e:
            return False, f"Login error: {str(e)}"
    
    def get_user_type(self, username):
        """Get user type based on username"""
        if username == 'root':
            return 'root'
        elif username in ['admin', 'doctor', 'nurse']:
            return 'admin'
        else:
            return 'guest'

